﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AMStudio.Common;
using Microsoft.Practices.ServiceLocation;
using System.Timers;
using System.Windows.Threading;

namespace AMStudio.UserInterface
{
	/// <summary>
	/// DialTableUserControl.xaml 的交互逻辑
	/// </summary>
	public partial class DialTableUserControl : UserControl
	{
        public DispatcherTimer atimer = new DispatcherTimer();
        public int n=0;
        public double start = 0;
        bool bRun = false;
		public DialTableUserControl()
		{
			this.InitializeComponent();
            //atimer.Interval = 2000;
            //atimer.Elapsed += new ElapsedEventHandler(atimer_Elapsed);
            atimer.Tick += new EventHandler(atimer_Tick);
            atimer.Interval = new TimeSpan(0,0,0,0,50);
            start = CyclePath.Start;
            bRun = false;
		}
        public void Run()
        {
            if (!bRun)
            {
                n = 0;
                CyclePath.Start = start - 0.06;
                atimer.Start();
                bRun = true;
            }
        }

        void atimer_Tick(object sender, EventArgs e)
        {
            CyclePath.Start += 0.01;
            n += 1;
            if (n > 5)
            {
                atimer.Stop();
                bRun = false;
            }
            //throw new NotImplementedException();
        }

        void atimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            CyclePath.Start += 0.1;
            //throw new NotImplementedException();
        }

		private void stn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            string index = btn.Name.Substring(3, btn.Name.Length - 3);
            if (index.Length == 1)
                index = "0" + index;
            string stationName = "StationUI" + index;
            AWinFormModule activeModule = ServiceLocator.Current.GetInstance<AWinFormModule>("MainUI");
            activeModule.Shell.ActiveModule(stationName);
			
        }

        private void PathListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
	}
}